<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>清除学习数据</title>
    <link rel="stylesheet" href="css/styles.css">
    <style>
        :root {
            --primary-color: #4a6cf7;
            --secondary-color: #f8f9fa;
            --accent-color: #ff6b6b;
            --text-color: #333;
            --success-color: #4CAF50;
            --error-color: #f44336;
            --background-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            --border-radius: 12px;
            --box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
            --transition: all 0.3s ease;
        }

        /* 加载动画 */
        #loader {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999;
            transition: opacity 0.5s ease-out, visibility 0.5s;
        }

        .loader-hidden {
            opacity: 0;
            visibility: hidden;
        }

        .loader-spinner {
            width: 50px;
            height: 50px;
            border: 5px solid #f3f3f3;
            border-top: 5px solid var(--primary-color);
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            text-align: center;
            background: var(--background-gradient);
            color: var(--text-color);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            opacity: 0;
            transition: opacity 0.5s ease-in;
        }

        .body-loaded {
            opacity: 1;
        }

        .container {
            background-color: white;
            padding: 40px;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            transition: var(--transition);
            transform: translateY(20px);
            opacity: 0;
        }

        .container-loaded {
            transform: translateY(0);
            opacity: 1;
        }

        .container:hover {
            box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
        }

        h1 {
            color: var(--primary-color);
            margin-bottom: 24px;
            font-size: 28px;
            font-weight: 700;
            position: relative;
            display: inline-block;
        }

        h1::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 60px;
            height: 4px;
            background-color: var(--accent-color);
            border-radius: 2px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .container-loaded h1::after {
            opacity: 1;
            transition-delay: 0.5s;
        }

        p {
            margin-bottom: 16px;
            line-height: 1.6;
            color: #555;
        }

        .warning-text {
            color: var(--accent-color);
            font-weight: 500;
            margin: 20px 0;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        button {
            background-color: var(--accent-color);
            color: white;
            border: none;
            padding: 14px 32px;
            font-size: 16px;
            border-radius: 30px;
            cursor: pointer;
            margin-top: 20px;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            font-weight: 500;
            box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
            position: relative;
            overflow: hidden;
        }

        button::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: all 0.5s;
        }

        button:hover::before {
            left: 100%;
        }

        button:hover {
            background-color: #e85a5a;
            transform: translateY(-2px);
            box-shadow: 0 6px 16px rgba(255, 107, 107, 0.4);
        }

        button:active {
            transform: translateY(0);
            box-shadow: 0 3px 8px rgba(255, 107, 107, 0.3);
        }

        .back-btn {
            background-color: transparent;
            color: var(--primary-color);
            border: 1px solid var(--primary-color);
            margin-left: 15px;
            box-shadow: none;
        }

        .back-btn:hover {
            background-color: var(--primary-color);
            color: white;
        }

        #status {
            margin-top: 24px;
            font-weight: bold;
            padding: 12px;
            border-radius: 8px;
            transition: var(--transition);
            opacity: 0;
            transform: translateY(10px);
        }

        .status-success {
            color: var(--success-color);
            background-color: rgba(76, 175, 80, 0.1);
            border: 1px solid var(--success-color);
            opacity: 1;
            transform: translateY(0);
            animation: fadeInUp 0.5s ease;
        }

        .status-error {
            color: var(--error-color);
            background-color: rgba(244, 67, 54, 0.1);
            border: 1px solid var(--error-color);
            opacity: 1;
            transform: translateY(0);
            animation: fadeInUp 0.5s ease;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .button-group {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 30px;
            flex-wrap: wrap;
        }

        .icon {
            font-size: 48px;
            margin-bottom: 20px;
            color: var(--accent-color);
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.1);
            }
            100% {
                transform: scale(1);
            }
        }

        /* 自定义确认对话框 */
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .modal-overlay.active {
            display: flex;
            opacity: 1;
        }

        .modal {
            background-color: white;
            border-radius: var(--border-radius);
            padding: 30px;
            max-width: 400px;
            width: 90%;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
            transform: translateY(-20px);
            transition: transform 0.3s ease;
        }

        .modal-overlay.active .modal {
            transform: translateY(0);
        }

        .modal h3 {
            color: var(--accent-color);
            margin-top: 0;
            margin-bottom: 15px;
        }

        .modal p {
            margin-bottom: 25px;
        }

        .modal-buttons {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        .modal-btn {
            padding: 10px 20px;
            border-radius: 25px;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .modal-btn.cancel {
            background-color: transparent;
            color: var(--text-color);
            border: 1px solid #ddd;
        }

        .modal-btn.cancel:hover {
            background-color: #f5f5f5;
        }

        .modal-btn.confirm {
            background-color: var(--accent-color);
            color: white;
            border: none;
        }

        .modal-btn.confirm:hover {
            background-color: #e85a5a;
        }

        /* 响应式设计优化 */
        @media (max-width: 576px) {
            .container {
                padding: 25px 15px;
            }

            h1 {
                font-size: 24px;
            }

            button {
                padding: 12px 24px;
                font-size: 14px;
            }

            .button-group {
                flex-direction: column;
                align-items: center;
            }

            .back-btn {
                margin-left: 0;
                margin-top: 10px;
            }
        }
    </style>
</head>
<body id="body">
    <!-- 加载动画 -->
    <div id="loader">
        <div class="loader-spinner"></div>
    </div>

    <div class="container" id="container">
        <div class="icon">⚠️</div>
        <h1>清除学习数据</h1>
        <p>点击下方按钮清除浏览器中存储的所有学习进度数据。</p>
        <p class="warning-text">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
                <line x1="12" y1="9" x2="12" y2="13"></line>
                <line x1="12" y1="17" x2="12.01" y2="17"></line>
            </svg>
            此操作将删除所有单词和句子的学习记录、积分和进度，且不可撤销！
        </p>
        <div class="button-group">
            <button id="clearBtn">清除数据</button>
            <button id="backBtn" class="back-btn">返回首页</button>
        </div>
        <div id="status"></div>
    </div>

    <!-- 自定义确认对话框 -->
    <div id="confirmModal" class="modal-overlay">
        <div class="modal">
            <h3>确认清除数据</h3>
            <p>确定要清除所有学习数据吗？此操作不可撤销！</p>
            <div class="modal-buttons">
                <button class="modal-btn cancel" id="cancelClear">取消</button>
                <button class="modal-btn confirm" id="confirmClear">确认清除</button>
            </div>
        </div>
    </div>

    <script>
        // 页面加载动画
        window.addEventListener('load', function() {
            setTimeout(function() {
                document.getElementById('loader').classList.add('loader-hidden');
                document.getElementById('body').classList.add('body-loaded');
                setTimeout(function() {
                    document.getElementById('container').classList.add('container-loaded');
                }, 200);
            }, 800);
        });

        // 自定义确认对话框逻辑
        const clearBtn = document.getElementById('clearBtn');
        const confirmModal = document.getElementById('confirmModal');
        const cancelClear = document.getElementById('cancelClear');
        const confirmClear = document.getElementById('confirmClear');
        const statusElement = document.getElementById('status');

        clearBtn.addEventListener('click', function() {
            confirmModal.classList.add('active');
        });

        cancelClear.addEventListener('click', function() {
            confirmModal.classList.remove('active');
        });

        // 点击对话框外部关闭
        confirmModal.addEventListener('click', function(e) {
            if (e.target === confirmModal) {
                confirmModal.classList.remove('active');
            }
        });

        // 确认清除数据
        confirmClear.addEventListener('click', function() {
            confirmModal.classList.remove('active');
            try {
                // 清除localStorage中的学习数据
                localStorage.removeItem('englishLearningProgress');
                localStorage.removeItem('learningStats');
                localStorage.removeItem('audioCache');
                localStorage.removeItem('lastReviewDate');

                // 清除其他可能的学习相关数据
                for (let i = 0; i < localStorage.length; i++) {
                    const key = localStorage.key(i);
                    if (key && (key.includes('english') || key.includes('learning') || key.includes('progress'))) {
                        localStorage.removeItem(key);
                        i--; // 因为删除后长度变化
                    }
                }

                // 显示成功消息并添加动画效果
                statusElement.textContent = '学习数据已成功清除！';
                statusElement.className = 'status-success';

                // 5秒后隐藏成功消息
                setTimeout(() => {
                    statusElement.className = '';
                }, 5000);
            } catch (error) {
                // 显示错误消息并添加动画效果
                statusElement.textContent = '清除数据时出错: ' + error.message;
                statusElement.className = 'status-error';
            }
        });

        // 返回首页按钮事件
        document.getElementById('backBtn').addEventListener('click', function() {
            window.location.href = 'index.html';
        });
    </script>
</body>
</html>